//
// File:	aprcfg.cpp
// Brief:	各table相关操作的实现
//
// History:
// ============================================================================
// 2011-01-17    Finux Chen <finuxchen@gmail.com>    创建
// 2011-02-17    Finux Chen <finuxchen@gmail.com>    添加光量项目相关操作
// 2011-03-07    Finux Chen <finuxchen@gmail.com>    range table更新
//

#include <iostream>
#include "aprcfg.h"

// 各range的默认值对应列表,当为bias时,lower为其默认值,upper无效
const rng_def_s	rngDefTblm[] = {
	{ PM_B999_nA,	500,	0 },
	{ PM_B9_99uA,	5.00,	0 },
	{ PM_B99_9uA,	50.0,	0 },
	{ PM_B999_uA,	500,	0 },
//	{ PM_B9_99mA,
	{ 0,			0,		0 }
};



// ==================================================================== 
//	func:	parameter keyword table								
//																		
//		I=电流	 	V=电压		D=Hue		H = Hue范围/倍率			
//		K=光量	 	O=未定义		T=安定时间	Z = Wait时间				
//		C=冷却时间	E=温度		L=逻辑设定								
//																		
// ==================================================================== 
const	prm_tbl_s	AprCfg::paramTblm[]={
//	param_name	,	param_code	,attribute		,bmode,	mmode										
	{"1000nA"	,	PM_B999_nA	,PM_BRANGE_ATTR	,'I',	' '},
	{"10.00uA"	,	PM_B9_99uA	,PM_BRANGE_ATTR	,'I',	' '},
	{"100.0uA"	,	PM_B99_9uA	,PM_BRANGE_ATTR	,'I',	' '},
	{"1000uA"	,	PM_B999_uA	,PM_BRANGE_ATTR	,'I',	' '},
	{"10.00mA"	,	PM_B9_99mA	,PM_BRANGE_ATTR	,'I',	' '},
	{"100.0mA"	,	PM_B99_9mA	,PM_BRANGE_ATTR	,'I',	' '},

	{"10.00V"	,	PM_B9_99V	,PM_BRANGE_ATTR	,'V',	' '},
//	{"NONE"		,	PM_BNOP		,PM_BRANGE_ATTR	,' ',	'0'},	// Finux
	{"10.00V"	,	PM_M9_99V	,PM_MRANGE_ATTR	,'V',	' '},
//	{"_9.99V"	,	PM_M_9_99V	,PM_MRANGE_ATTR	,'V',	' '},
	{"770.0nm"	,	PM_MHUEnm	,PM_MRANGE_ATTR	,'D',	' '},

//	{"770.0nm"	,	PM_M770nm	,PM_MRANGE_ATTR	,'D',	' '},	
//	{"950.0nm"	,	PM_M950nm	,PM_MRANGE_ATTR	,'D',	' '},	
	{"1000nA"	,	PM_M999_nA	,PM_MRANGE_ATTR	,'I',	' '},
	{"10.00uA"	,	PM_M9_99uA	,PM_MRANGE_ATTR	,'I',	' '},
	{"100.0uA"	,	PM_M99_9uA	,PM_MRANGE_ATTR	,'I',	' '},
	{"1000uA"	,	PM_M999_uA	,PM_MRANGE_ATTR	,'I',	' '},
	{"10.00mA"	,	PM_M9_99mA	,PM_MRANGE_ATTR	,'I',	' '},
	{"100.0mA"	,	PM_M99_9mA	,PM_MRANGE_ATTR	,'I',	' '},

	{"100.0nA"	,	PM_H100_0nA	,PM_HUERNG_ATTR	,'H',	' '},
	{"1.000uA"	,	PM_H1_000uA	,PM_HUERNG_ATTR	,'H',	' '},
	{"10.00uA"	,	PM_H10_00uA	,PM_HUERNG_ATTR	,'H',	' '},

	{"999.9%"	,	PM_VL999_9	,PM_MRANGE_ATTR	,'K',	' '},
	{"9.99mcd"	,	PM_VL9_99u	,PM_MRANGE_ATTR	,'K',	'K'},
	{"99.9mcd"	,	PM_VL99_9u	,PM_MRANGE_ATTR	,'K',	'K'},
	{"999mcd"	,	PM_VL999u	,PM_MRANGE_ATTR	,'K',	'K'},

	{"9.999"	,	PM_M_RATIO	,PM_MRANGE_ATTR	,'R',	' '},
	{"_.___"	,	PM_DLMXY	,PM_MRANGE_ATTR	,'M',	' '},
	{"___"		,	PM_DLMXYJ	,PM_MRANGE_ATTR	,'M',	' '},
	{"x1"		,	PM_HX1		,PM_HUESCF_ATTR	,'H',	' '},
	{"x2"		,	PM_HX2		,PM_HUESCF_ATTR	,'H',	' '},
	{"x3"		,	PM_HX3		,PM_HUESCF_ATTR	,'H',	' '},
	{"x4"		,	PM_HX4		,PM_HUESCF_ATTR	,'H',	' '},
	{"x6"		,	PM_HX6		,PM_HUESCF_ATTR	,'H',	' '},
	{"x8"		,	PM_HX8		,PM_HUESCF_ATTR	,'H',	' '},
	{"x12"		,	PM_HX12		,PM_HUESCF_ATTR	,'H',	' '},
	{"x24"		,	PM_HX24		,PM_HUESCF_ATTR	,'H',	' '},

	{"TEMP"		,	PM_TEMP		,PM_HUETMP_ATTR	,'H',	' '},

	{"NONE"		,	PM_MNOP		,PM_MRANGE_ATTR	,' ',	'0'},
	{"OFF"		,	PM_OFF		,PM_ONOFF_ATTR	,' ',	' '},	// OFF
	{"ON"		,	PM_ON		,PM_ONOFF_ATTR	,' ',	' '},	// ON	
	{"DEL"		,	PM_DEL		,PM_DEL_ATTR	,' ',	' '},	// DEL
	{"MANUAL"	,	PM_MANUAL	,PM_MMODE_ATTR	,' ',	' '},	// MAN
	{"REPEAT"	,	PM_REPEAT	,PM_MMODE_ATTR	,' ',	' '},	// REPEAT
	{"AUTO"		,	PM_AUTO		,PM_MMODE_ATTR	,' ',	' '},	// AUTO
	{"50Hz"		,	PM_50HZ		,PM_FILFREQ_ATTR,' ',	' '},	
	{"60Hz"		,	PM_60HZ		,PM_FILFREQ_ATTR,' ',	' '},
	{"OFF"		,	PM_FOFF		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ON(1)"	,	PM_F1		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ON(2)"	,	PM_F2		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ON(4)"	,	PM_F4		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ON(8)"	,	PM_F8		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ON(16)"	,	PM_F16		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
	{"ASYNC"	,	PM_ASYNC	,PM_FIL_ATTR	,' ',	' '},	// FILTER	

	{"1C2_CCOM"	,PM_DEV_1C2CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"1C2_ACOM"	,PM_DEV_1C2ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C4_CCOM"	,PM_DEV_2C4CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C4_ACOM"	,PM_DEV_2C4ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C4_1C2A"	,PM_DEV_2C41C2A	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C4_1A2C"	,PM_DEV_2C41A2C	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C3_CCOM"	,PM_DEV_2C3CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C3_ACOM"	,PM_DEV_2C3ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C3_1C2A"	,PM_DEV_2C31C2A	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"2C3_1A2C"	,PM_DEV_2C31A2C	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C4_CCOM"	,PM_DEV_3C4CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C4_ACOM"	,PM_DEV_3C4ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_CCOM"	,PM_DEV_3C6CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_ACOM"	,PM_DEV_3C6ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2CRA"	,PM_DEV_3C62CRA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2CCA"	,PM_DEV_3C62CCA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2ALC"	,PM_DEV_3C62ALC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2CLA"	,PM_DEV_3C62CLA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2ACC"	,PM_DEV_3C62ACC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	{"3C6_2ARC"	,PM_DEV_3C62ARC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
	//85
	{"VF"		,	PM_VF		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"IF"		,	PM_IF		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
	{"VR"		,	PM_VR		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"IR"		,	PM_IR		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
	{"HUE"		,	PM_HUE		,PM_ITEM_ATTR	,'I',	'D'},	// ITEM		
	{"HUEI"		,	PM_HUEI		,PM_ITEM_ATTR	,'V',	'D'},	// ITEM		
	{"POLV"		,	PM_POLV		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"POLI"		,	PM_POLI		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
	{"POLH"		,	PM_POLH		,PM_ITEM_ATTR	,'I',	'D'},	// ITEM		
	{"DCC"		,	PM_ESD		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"VLV"		,	PM_VLV		,PM_ITEM_ATTR	,'I',	'K'},	// ITEM		
	{"VLI"		,	PM_VLI		,PM_ITEM_ATTR	,'V',	'K'},	// ITEM		
	{"KLVC"		,	PM_KLVC		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"KLVH"		,	PM_KLVH		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
	{"DLMX"		,	PM_DLMX		,PM_ITEM_ATTR	,'I',	'M'},	// ITEM		
	{"DLMY"		,	PM_DLMY		,PM_ITEM_ATTR	,'I',	'M'},	// ITEM		
//	{"NOP"		,	PM_NOP		,PM_ITEM_ATTR	,'0',	'0'},	// ITEM		// 对于界面设定,应该不需要该项, Finux

	{NULL		,	0			,0				,0	,	0}	// terminate	
};
//const prm_tbl_s AprCfg::paramTblm[] = {
////	param_name	,	param_code	,attribute		,bmode,	mmode										
//	{"999nA"	,	PM_B999_nA	,PM_BRANGE_ATTR	,'I',	' '},	// 加电范围
//	{"9.99uA"	,	PM_B9_99uA	,PM_BRANGE_ATTR	,'I',	' '},
//	{"99.9uA"	,	PM_B99_9uA	,PM_BRANGE_ATTR	,'I',	' '},
//	{"320uA"	,	PM_B999_uA	,PM_BRANGE_ATTR	,'I',	' '},
//	{"3.20mA"	,	PM_B9_99mA	,PM_BRANGE_ATTR	,'I',	' '},
//	{"32.0mA"	,	PM_B99_9mA	,PM_BRANGE_ATTR	,'I',	' '},
//
//	{"9.99V"	,	PM_B9_99V	,PM_BRANGE_ATTR	,'V',	' '},
////	{"NONE"		,	PM_BNOP		,PM_BRANGE_ATTR	,' ',	'0'},	// Finux, 2011-02-24
//	{"9.99V"	,	PM_M9_99V	,PM_MRANGE_ATTR	,'V',	' '},	// 测定范围
////	{"_9.99V"	,	PM_M_9_99V	,PM_MRANGE_ATTR	,'V',	' '},	// 测定范围(±)
//	{"770.0nm"	,	PM_MHUEnm	,PM_MRANGE_ATTR	,'D',	' '},
//
////	{"770.0nm"	,	PM_M770nm	,PM_MRANGE_ATTR	,'D',	' '},	
////	{"950.0nm"	,	PM_M950nm	,PM_MRANGE_ATTR	,'D',	' '},	
//	{"320nA"	,	PM_M999_nA	,PM_MRANGE_ATTR	,'I',	' '},
//	{"3.20uA"	,	PM_M9_99uA	,PM_MRANGE_ATTR	,'I',	' '},
//	{"32.0uA"	,	PM_M99_9uA	,PM_MRANGE_ATTR	,'I',	' '},
//	{"320uA"	,	PM_M999_uA	,PM_MRANGE_ATTR	,'I',	' '},
//	{"3.20mA"	,	PM_M9_99mA	,PM_MRANGE_ATTR	,'I',	' '},
//	{"32.0mA"	,	PM_M99_9mA	,PM_MRANGE_ATTR	,'I',	' '},
//
//	{"100.0nA"	,	PM_H100_0nA	,PM_HUERNG_ATTR	,'H',	' '},
//	{"1.000uA"	,	PM_H1_000uA	,PM_HUERNG_ATTR	,'H',	' '},
//	{"10.00uA"	,	PM_H10_00uA	,PM_HUERNG_ATTR	,'H',	' '},
//
//	{"999.9%"	,	PM_VL999_9	,PM_MRANGE_ATTR	,'K',	' '},
//	{"9.99mcd"	,	PM_VL9_99u	,PM_MRANGE_ATTR	,'K',	'K'},
//	{"99.9mcd"	,	PM_VL99_9u	,PM_MRANGE_ATTR	,'K',	'K'},
//	{"999mcd"	,	PM_VL999u	,PM_MRANGE_ATTR	,'K',	'K'},
//
//	{"9.999"	,	PM_M_RATIO	,PM_MRANGE_ATTR	,'R',	' '},
//	{"_.___"	,	PM_DLMXY	,PM_MRANGE_ATTR	,'M',	' '},
//	{"___"		,	PM_DLMXYJ	,PM_MRANGE_ATTR	,'M',	' '},
//	{"x1"		,	PM_HX1		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x2"		,	PM_HX2		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x3"		,	PM_HX3		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x4"		,	PM_HX4		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x6"		,	PM_HX6		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x8"		,	PM_HX8		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x12"		,	PM_HX12		,PM_HUESCF_ATTR	,'H',	' '},
//	{"x24"		,	PM_HX24		,PM_HUESCF_ATTR	,'H',	' '},
//
//	{"TEMP"		,	PM_TEMP		,PM_HUETMP_ATTR	,'H',	' '},
//
//	{"NONE"		,	PM_MNOP		,PM_MRANGE_ATTR	,' ',	'0'},
//	{"OFF"		,	PM_OFF		,PM_ONOFF_ATTR	,' ',	' '},	// OFF
//	{"ON"		,	PM_ON		,PM_ONOFF_ATTR	,' ',	' '},	// ON	
//	{"DEL"		,	PM_DEL		,PM_DEL_ATTR	,' ',	' '},	// DEL
//	{"MANUAL"	,	PM_MANUAL	,PM_MMODE_ATTR	,' ',	' '},	// MAN
//	{"REPEAT"	,	PM_REPEAT	,PM_MMODE_ATTR	,' ',	' '},	// REPEAT
//	{"AUTO"		,	PM_AUTO		,PM_MMODE_ATTR	,' ',	' '},	// AUTO
//	{"50Hz"		,	PM_50HZ		,PM_FILFREQ_ATTR,' ',	' '},	
//	{"60Hz"		,	PM_60HZ		,PM_FILFREQ_ATTR,' ',	' '},
//	{"OFF"		,	PM_FOFF		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ON(1)"	,	PM_F1		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ON(2)"	,	PM_F2		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ON(4)"	,	PM_F4		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ON(8)"	,	PM_F8		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ON(16)"	,	PM_F16		,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//	{"ASYNC"	,	PM_ASYNC	,PM_FIL_ATTR	,' ',	' '},	// FILTER	
//
//	{"1C2_CCOM"	,PM_DEV_1C2CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"1C2_ACOM"	,PM_DEV_1C2ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C4_CCOM"	,PM_DEV_2C4CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C4_ACOM"	,PM_DEV_2C4ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C4_1C2A"	,PM_DEV_2C41C2A	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C4_1A2C"	,PM_DEV_2C41A2C	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C3_CCOM"	,PM_DEV_2C3CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C3_ACOM"	,PM_DEV_2C3ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C3_1C2A"	,PM_DEV_2C31C2A	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"2C3_1A2C"	,PM_DEV_2C31A2C	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C4_CCOM"	,PM_DEV_3C4CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C4_ACOM"	,PM_DEV_3C4ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_CCOM"	,PM_DEV_3C6CCOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_ACOM"	,PM_DEV_3C6ACOM	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2CRA"	,PM_DEV_3C62CRA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2CCA"	,PM_DEV_3C62CCA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2ALC"	,PM_DEV_3C62ALC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2CLA"	,PM_DEV_3C62CLA	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2ACC"	,PM_DEV_3C62ACC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	{"3C6_2ARC"	,PM_DEV_3C62ARC	,PM_DEV_ATTR	,' ',	' '},	// DEVICE	
//	//85
//	{"VF"		,	PM_VF		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"IF"		,	PM_IF		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
//	{"VR"		,	PM_VR		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"IR"		,	PM_IR		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
//	{"HUE"		,	PM_HUE		,PM_ITEM_ATTR	,'I',	'D'},	// ITEM		
//	{"HUEI"		,	PM_HUEI		,PM_ITEM_ATTR	,'V',	'D'},	// ITEM		
//	{"POLV"		,	PM_POLV		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"POLI"		,	PM_POLI		,PM_ITEM_ATTR	,'V',	'I'},	// ITEM		
//	{"POLH"		,	PM_POLH		,PM_ITEM_ATTR	,'I',	'D'},	// ITEM		
//	{"DCC"		,	PM_ESD		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"VLV"		,	PM_VLV		,PM_ITEM_ATTR	,'I',	'K'},	// ITEM		
//	{"VLI"		,	PM_VLI		,PM_ITEM_ATTR	,'V',	'K'},	// ITEM		
//	{"KLVC"		,	PM_KLVC		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"KLVH"		,	PM_KLVH		,PM_ITEM_ATTR	,'I',	'V'},	// ITEM		
//	{"DLMX"		,	PM_DLMX		,PM_ITEM_ATTR	,'I',	'M'},	// ITEM		
//	{"DLMY"		,	PM_DLMY		,PM_ITEM_ATTR	,'I',	'M'},	// ITEM		
////	{"NOP"		,	PM_NOP		,PM_ITEM_ATTR	,'0',	'0'},	// ITEM		// 应该不需要
//
//	{NULL		,	0			,0				,0	,	0}	// terminate	
//};

// =============================================================================
//	func: 精密插补范围定义表
/*	例
		fullscale 100.0 在 A/D 和 D/A (32767) 的换算系数
		scl = 100.0/32767 = 3.05185e-3
		D/A 输出的时候需要加 offset 0x8000
*/
// =============================================================================
const	rng_tbl_s	AprCfg::rangeTblm[]={
/*	fmt		,unit ,c,	code,	,hi,	low,	step,	coef,	mode,	scale,		offset*/
	{"%5.0f","nA ",4,PM_B999_nA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0x8000L},	// PM_B999_nA = 1
	{"%5.2f","uA ",4,PM_B9_99uA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0x8000L},	// PM_B9_99uA = 2
	{"%5.1f","uA ",4,PM_B99_9uA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0x8000L},	// PM_B99_9uA = 3
	{"%5.0f","uA ",4,PM_B999_uA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0x8000L},	// PM_B999_uA = 4
	{"%5.2f","mA ",4,PM_B9_99mA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0x8000L},	// PM_B9_99mA = 5
	{"%5.1f","mA ",4,PM_B99_9mA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0x8000L},	// PM_B99_9mA = 6
	{"%5.0f","nA ",4,PM_M999_nA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0L},		// PM_M999_nA = 14
	{"%5.2f","uA ",4,PM_M9_99uA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0L},		// PM_M9_99uA = 15
	{"%5.1f","uA ",3,PM_M99_9uA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0L},		// PM_M99_9uA = 16
	{"%5.0f","uA ",3,PM_M999_uA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0L},		// PM_M999_uA = 17
	{"%5.2f","mA ",3,PM_M9_99mA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0L},		// PM_M9_99mA = 18
	{"%5.1f","mA ",3,PM_M99_9mA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0L},		// PM_M99_9mA = 19
	
	{"%5.2f","V  ",4,PM_B9_99V	,10.00,	0.0,	0.01,	100L,	'V', 3.05185e-4,	0x8000L},	// PM_B9_99V  = 7
	{"%5.2f","V  ",4,PM_M9_99V	,10.00,	0.0,	0.01,	100L,	'V', 3.05185e-4,	0L},		// PM_M9_99V  = 9
//	{"%5.2f","V  ",4,PM_M_9_99V	,9.90,	-10.00,	0.01,	100L,	'V', 3.05185e-4,	0L},		// PM_M_9_99V = 10
	
	{"%5.2f","uA ",4,PM_H10_00uA,10.0,	0.0,	0.01,	100L,	'H', 3.05185e-4,	0L},		// PM_H10_00uA= 20
	{"%5.3f","uA ",4,PM_H1_000uA,1.0,	0.0,	0.001,	1000L,	'H', 3.05185e-5,	0L},		// PM_H1_000uA= 21
	{"%5.1f","nA ",4,PM_H100_0nA,100.0, 0.0,	0.1,	10L,	'H', 3.05185e-3,	0L},		// PM_H100_0nA= 22
	{"%4.1f","~C ",3,PM_TEMP	,50.0,	0.0,	0.1,	10L,	'E',-1.01723e-3,	-24575L},	// PM_TEMP    = 36

	{"%5.1f","nm ",4,PM_MHUEnm	,20.0,	-20.0,	0.1,	10L,	'D', 0.1,			0L},
	{"%5.1f","nm ",4,PM_M770nm	,680.0,	450.0,	0.1,	10L,	'D', 0.1,			0L},
	{"%5.1f","nm ",4,PM_M950nm	,950.0,	680.0,	0.1,	10L,	'D', 0.1,			0L},
	{"%5.1f","ms" ,4,PM_T9999ms	,999.9,	0.5,	0.1,	10L,	'T', 1.0,			0L},
	{"%4.1f","ms ",4,PM_T99_9ms	,20.0,	0.4,	0.1,	10L,	'Z', 1.0,			0L},
	{"%4.1f","V  ",2,PM_L9_99V	,10.0,	0.5,	0.1,	10L,	'V', 3.05185e-4,	0x8000L},
	{"%5.0f","ms" ,4,PM_COOLT	,10000,	0.0,	10.0,	1L,		'C', 1.0,			0L},
	{"%5.1f","%  ",4,PM_VL999_9	,999.9,	0.0,	0.1,	10L,	'K', 1.0,			0L},
	{"%5.2f","mcd",3,PM_VL9_99u	,9.990,	0.0,	0.01,	100L,	'K', 1.0,			0L},
	{"%5.1f","mcd",3,PM_VL99_9u	,99.90,	0.0,	0.1,	10L,	'K', 1.0,			0L},
	{"%5.0f","mcd",4,PM_VL999u	,9999.0,0.0,	1.0,	1L,		'K', 1.0,			0L},
	{"%5.1f","%  ",4,PM_M_RATIO	,999.9, 0.0,	0.1,	10L,	'R', 1.0,			0L},
	{"%5.0f","-- ",0,PM_BNOP	,0.0,	0.0,	1.0,	1L,		'0', 1.0,			0L},
	{"%5.0f","-- ",0,PM_MNOP	,0.0,	0.0,	1.0,	1L,		'0', 1.0,			0L},

	{"%4X"	,"-- ",6,PM_LOGIC	,65535.0,0.0,	1.0,	1L,		'L', 1.0,			0L},
	{"%3d"	,"%  ",3,PM_RATIO	,100.0 ,0.0,	1.0,	1L,		'L', 1.0,			0L},
	{"%3d"	,"   ",3,PM_COUNT	,100.0 ,0.0,	1.0,	1L,		'L', 1.0,			0L},
	{"%6.3f"," "  ,4,PM_DLMXY	,0.900,	0.050,	0.001,	1000L,	'M', 1.0,			0L},
	{"%6.3f"," "  ,4,PM_DLMXYJ	,0.100,-0.100,	0.001,	1000L,	'M', 1.0,			0L},
	{"%7.4f",""   ,5,PM_DLMADJ	,1.0000,0.0000,0.0001,	10000L,	'M', 1.0,			0L},
	{NULL	,""	  ,0,0			,0.0,	0.0,	0.0,	1L,		' ', 1.0,			0L}
};
//const rng_tbl_s AprCfg::rangeTblm[] = {
///*	fmt		,unit ,c,	code,	,hi,	low,	step,	coef,	mode,	scale,		offset*/
//	{"%5.0f","nA ",4,PM_B999_nA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0x8000L},	// PM_B999_nA = 1
//	{"%5.2f","uA ",4,PM_B9_99uA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0x8000L},	// PM_B9_99uA = 2
//	{"%5.1f","uA ",4,PM_B99_9uA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0x8000L},	// PM_B99_9uA = 3
//	{"%5.0f","uA ",4,PM_B999_uA	,1000,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0x8000L},	// PM_B999_uA = 4
//	{"%5.2f","mA ",4,PM_B9_99mA	,10.00,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0x8000L},	// PM_B9_99mA = 5
//	{"%5.1f","mA ",4,PM_B99_9mA	,100.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0x8000L},	// PM_B99_9mA = 6
//	{"%5.0f","nA ",4,PM_M999_nA	,320.0,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0L},		// PM_M999_nA = 14
//	{"%5.2f","uA ",4,PM_M9_99uA	,3.20,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0L},		// PM_M9_99uA = 15
//	{"%5.1f","uA ",3,PM_M99_9uA	,32.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0L},		// PM_M99_9uA = 16
//	{"%5.0f","uA ",3,PM_M999_uA	,320.0,	0.0,	1.0,	1L,		'I', 3.05185e-2,	0L},		// PM_M999_uA = 17
//	{"%5.2f","mA ",3,PM_M9_99mA	,3.20,	0.0,	0.01,	100L,	'I', 3.05185e-4,	0L},		// PM_M9_99mA = 18
//	{"%5.1f","mA ",3,PM_M99_9mA	,32.0,	0.0,	0.1,	10L,	'I', 3.05185e-3,	0L},		// PM_M99_9mA = 19
//	
//	{"%5.2f","V  ",4,PM_B9_99V	,9.90,	0.0,	0.01,	100L,	'V', 3.05185e-4,	0x8000L},	// PM_B9_99V  = 7
//	{"%5.2f","V  ",4,PM_M9_99V	,9.90,	0.0,	0.01,	100L,	'V', 3.05185e-4,	0L},		// PM_M9_99V  = 9
////	{"%5.2f","V  ",4,PM_M_9_99V	,9.90,	-10.00,	0.01,	100L,	'V', 3.05185e-4,	0L},		// PM_M_9_99V = 10
//	
//	{"%5.2f","uA ",4,PM_H10_00uA,10.0,	0.0,	0.01,	100L,	'H', 3.05185e-4,	0L},		// PM_H10_00uA= 20
//	{"%5.3f","uA ",4,PM_H1_000uA,1.0,	0.0,	0.001,	1000L,	'H', 3.05185e-5,	0L},		// PM_H1_000uA= 21
//	{"%5.1f","nA ",4,PM_H100_0nA,100.0, 0.0,	0.1,	10L,	'H', 3.05185e-3,	0L},		// PM_H100_0nA= 22
//	{"%4.1f","~C ",3,PM_TEMP	,50.0,	0.0,	0.1,	10L,	'E',-1.01723e-3,	-24575L},	// PM_TEMP    = 36
//
//	{"%5.1f","nm ",4,PM_MHUEnm	,20.0,	-20.0,	0.1,	10L,	'D', 0.1,			0L},
//	{"%5.1f","nm ",4,PM_M770nm	,680.0,	450.0,	0.1,	10L,	'D', 0.1,			0L},
//	{"%5.1f","nm ",4,PM_M950nm	,950.0,	680.0,	0.1,	10L,	'D', 0.1,			0L},
//	{"%5.1f","ms" ,4,PM_T9999ms	,999.9,	0.5,	0.1,	10L,	'T', 1.0,			0L},
//	{"%4.1f","ms ",4,PM_T99_9ms	,20.0,	0.4,	0.1,	10L,	'Z', 1.0,			0L},
//	{"%4.1f","V  ",2,PM_L9_99V	,10.0,	0.5,	0.1,	10L,	'V', 3.05185e-4,	0x8000L},
//	{"%5.0f","ms" ,4,PM_COOLT	,10000,	0.0,	10.0,	1L,		'C', 1.0,			0L},
//	{"%5.1f","%  ",4,PM_VL999_9	,999.9,	0.0,	0.1,	10L,	'K', 1.0,			0L},
//	{"%5.2f","mcd",3,PM_VL9_99u	,9.990,	0.0,	0.01,	100L,	'K', 1.0,			0L},
//	{"%5.1f","mcd",3,PM_VL99_9u	,99.90,	0.0,	0.1,	10L,	'K', 1.0,			0L},
//	{"%5.0f","mcd",4,PM_VL999u	,9999.0,0.0,	1.0,	1L,		'K', 1.0,			0L},
//	{"%5.1f","%  ",4,PM_M_RATIO	,999.9, 0.0,	0.1,	10L,	'R', 1.0,			0L},
//	{"%5.0f","-- ",0,PM_BNOP	,0.0,	0.0,	1.0,	1L,		'0', 1.0,			0L},
//	{"%5.0f","-- ",0,PM_MNOP	,0.0,	0.0,	1.0,	1L,		'0', 1.0,			0L},
//
//	{"%4X"	,"-- ",6,PM_LOGIC	,65535.0,0.0,	1.0,	1L,		'L', 1.0,			0L},
//	{"%3d"	,"%  ",3,PM_RATIO	,100.0 ,0.0,	1.0,	1L,		'L', 1.0,			0L},
//	{"%3d"	,"   ",3,PM_COUNT	,100.0 ,0.0,	1.0,	1L,		'L', 1.0,			0L},
//	{"%6.3f"," "  ,4,PM_DLMXY	,0.900,	0.050,	0.001,	1000L,	'M', 1.0,			0L},
//	{"%6.3f"," "  ,4,PM_DLMXYJ	,0.100,-0.100,	0.001,	1000L,	'M', 1.0,			0L},
//	{"%7.4f",""   ,5,PM_DLMADJ	,1.0000,0.0000, 0.0001,	10000L,	'M', 1.0,			0L},
//	{NULL	,""	  ,0,0			,0.0,	0.0,	0.0,	1L,		' ', 1.0,			0L}
//};

// ================================================================================
//	func:	device 控制表（三通道）
/* ↑↓→←

		大多数情况下, 通过切换逻辑通道就足够了,
		但3C4A、3C4C仅仅进行逻辑通道的切换是不够的，必须要切换物理通道才行
		
		PM_DEV_1C2CCOM,		← device type code
		
							通常时一组
		{{1,2,3,0,0},		← relay pattern, 端子对应的物理通路, 
								(0=COM, 1=CH1, 2=CH2, 3=CH3) 
								最后一位标志物理通道是否切换到特殊情况(0-正常;1-特殊)
								
			{ 1, 2, 3},		← 物理通路对应的逻辑通道, 逻辑通路是本质的
								(1=ch1, 2=ch2, 3=ch3)
			{ 1, 1, 1}},	← 极性
								(1=C-COM, -1=A-COM)
								
							反转时一组
		{{1,2,3,0,0},
			{ 1, 2, 3},
			{-1,-1,-1}}

*/
// ================================================================================
const devtbl_s AprCfg::devTblm[] = {
	{
		PM_DEV_1C2CCOM,			// PM_DEV_1C2CCOM = 57
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}},
		{{1,2,3,0,0},{1,2,3},{-1,-1,-1}}
	},{
		PM_DEV_1C2ACOM,			// PM_DEV_1C2ACOM = 58
		{{1,2,3,0,0},{1,2,3},{-1,-1,-1}},
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}}
	},{
		PM_DEV_2C4CCOM,			// PM_DEV_2C4CCOM = 59
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}},
		{{1,2,3,0,0},{2,1,3},{-1,-1, 1}}
	},{
		PM_DEV_2C4ACOM,			// PM_DEV_2C4ACOM = 60
		{{1,2,3,0,0},{1,2,3},{-1,-1, 1}},
		{{1,2,3,0,0},{2,1,3},{ 1, 1, 1}}
	},{
		PM_DEV_2C41C2A,			// PM_DEV_2C41C2A = 61
		{{1,2,3,0,0},{1,2,3},{ 1,-1, 1}},
		{{1,2,3,0,0},{2,1,3},{ 1,-1, 1}}
	},{
		PM_DEV_2C41A2C,			// PM_DEV_2C41A2C = 62
		{{1,2,3,0,0},{1,2,3},{-1, 1, 1}},
		{{1,2,3,0,0},{2,1,3},{-1, 1, 1}}
	},{
		PM_DEV_2C3CCOM,			// PM_DEV_2C3CCOM = 63
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}},
		{{1,2,3,0,0},{2,1,3},{ 1, 1, 1}}
	},{
		PM_DEV_2C3ACOM,			// PM_DEV_2C3ACOM = 64
		{{1,2,3,0,0},{1,2,3},{-1,-1, 1}},
		{{1,2,3,0,0},{2,1,3},{-1,-1, 1}}
	},{
		PM_DEV_2C31C2A,			// PM_DEV_2C31C2A = 65
		{{1,2,3,0,0},{1,2,3},{ 1,-1, 1}},
		{{1,2,3,0,0},{2,1,3},{-1, 1, 1}}
	},{
		PM_DEV_2C31A2C,			// PM_DEV_2C31A2C = 66
		{{1,2,3,0,0},{1,2,3},{-1, 1, 1}},
		{{1,2,3,0,0},{2,1,3},{ 1,-1, 1}}
	},{
		PM_DEV_3C4CCOM,			// PM_DEV_3C4CCOM = 67
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}},
		{{1,0,3,2,1},{3,2,1},{ 1, 1, 1}}
	},{
		PM_DEV_3C4ACOM,			// PM_DEV_3C4ACOM = 68
		{{1,2,3,0,0},{1,2,3},{-1,-1,-1}},
		{{1,0,3,2,1},{3,2,1},{-1,-1,-1}}
	},{
		PM_DEV_3C6CCOM,			// PM_DEV_3C6CCOM = 69
		{{1,2,3,0,0},{1,2,3},{ 1, 1, 1}},
		{{1,2,3,0,0},{3,2,1},{-1,-1,-1}}
	},{
		PM_DEV_3C6ACOM,			// PM_DEV_3C6ACOM = 70
		{{1,2,3,0,0},{1,2,3},{-1,-1,-1}},
		{{1,2,3,0,0},{3,2,1},{ 1, 1, 1}}
	},{
		PM_DEV_3C62CRA,			// PM_DEV_3C62CRA = 71
		{{1,2,3,0,0},{1,2,3},{ 1, 1,-1}},
		{{1,2,3,0,0},{3,2,1},{ 1,-1,-1}}
	},{
		PM_DEV_3C62CCA,			// PM_DEV_3C62CCA = 72
		{{1,2,3,0,0},{1,2,3},{ 1,-1, 1}},
		{{1,2,3,0,0},{3,2,1},{-1, 1,-1}}
	},{
		PM_DEV_3C62ALC,			// PM_DEV_3C62ALC = 73
		{{1,2,3,0,0},{1,2,3},{ 1,-1,-1}},
		{{1,2,3,0,0},{3,2,1},{ 1, 1,-1}}
	},{
		PM_DEV_3C62CLA,			// PM_DEV_3C62CLA = 74
		{{1,2,3,0,0},{1,2,3},{-1, 1, 1}},
		{{1,2,3,0,0},{3,2,1},{-1,-1, 1}}
	},{
		PM_DEV_3C62ACC,			// PM_DEV_3C62ACC = 75
		{{1,2,3,0,0},{1,2,3},{-1, 1,-1}},
		{{1,2,3,0,0},{3,2,1},{ 1,-1, 1}}
	},{
		PM_DEV_3C62ARC,			// PM_DEV_3C62ARC = 76
		{{1,2,3,0,0},{1,2,3},{-1,-1, 1}},
		{{1,2,3,0,0},{3,2,1},{-1, 1, 1}}
	},{
		-1,
		{{0,0,0,0,0},{0,0,0},{ 0, 0, 0}},
		{{0,0,0,0,0},{0,0,0},{ 0, 0, 0}}
	}
};

//// 光量相关表定义 /////////////////////////////////////////////////////////

// useMaster项目
const short AprCfg::usemitem[] 	=
			 { PM_POLH, PM_HUE, PM_HUEI, PM_VLV, PM_VLI, PM_DLMX, PM_DLMY, 0 };
// hue项目
const short AprCfg::hueitem[]	= { PM_POLH, PM_HUE, PM_HUEI, 0 };
// vl项目
const short AprCfg::vlitem[] 	= { PM_VLV, PM_VLI, 0 };
// dlm项目
const short AprCfg::lmitem[]	= { PM_DLMX, PM_DLMY, 0 };



//// 通用查表操作 ////////////////////////////////////////////////////////////

//
// 根据step计算小数位数
//
static void getDecimalsByStep(_IN double step, _OUT ushort &decimals){
    ushort decimalsTmp	= 0;
    double stepTmp		= step;
    if(0 == stepTmp){
        decimalsTmp = 0;
    }else{
        while(stepTmp < 1){
            stepTmp *= 10;
            ++decimalsTmp;
        }
    }
    decimals = decimalsTmp;
}

//
// 根据参数名commandName和参数属性attr在参数table中检索对应code
//
bool AprCfg::getParamCodeByName(_IN		const QString	&name,
							    _IN		para_attr_e		attr,
							    _OUT	ushort			&code)
{
	ushort index = 0;

	while(paramTblm[index].commandName != NULL){
	
		if(name == paramTblm[index].commandName && attr == paramTblm[index].attr){
			code = paramTblm[index].code;
			return true;
		}
		++index;
	}

	return false;
}

//
// 根据参数code查找参数名
//	
bool AprCfg::getParamNameByCode(_IN ushort code, _OUT QString &name)
{
	ushort index = 0;

	while(paramTblm[index].commandName != NULL){
		if(paramTblm[index].code == code){
			name = paramTblm[index].commandName;
			return true;
		}
		++index;
	}

	return false;
}

//
// 根据attr返回同一类型所有字符串
// 用于获取所有ITEM名,DEVICE名或其他一些选项,主要供UI使用
//
bool AprCfg::getNamesByAttr(_IN	 para_attr_e attr, 
                            _OUT QStringList &names)
{
	bool ret = false;
	QString name;

	names.clear();

	ushort index = 0;
	while(paramTblm[index].commandName != NULL){
		if(attr == paramTblm[index].attr){
			name = paramTblm[index].commandName;
			names << name;
			ret = true;
		}
		++index;
	}

	return ret;
}

//
// 查找相关ITEM的所有range列表
//
bool AprCfg::getRangesByItem(_IN	const QString 	&item, 
							 _IN	para_attr_e 	attr, 
                             _OUT	QStringList		&ranges)
{
	char mode;

	if(!getBiasMeasModeByItem(item, attr, mode)){
		return false;
	}
	
	bool ret = false;
	QString range;

	ranges.clear();

	ushort index = 0;
	while(paramTblm[index].commandName != NULL){
		if(attr == paramTblm[index].attr){
			if(mode == paramTblm[index].bmode){
				range = paramTblm[index].commandName;
				ranges << range;
				ret = true;
			}
		}
		++index;
	}

	return ret;
}
								
//
// 根据Range的描述字符串,得到其详细设置
//
bool AprCfg::getRangeDetailByName(_IN 	const QString	&range,
								  _IN 	para_attr_e 	attr,
								  _OUT 	double 			&upper,
								  _OUT 	double 			&lower,
								  _OUT 	double 			&step,
								  _OUT 	ushort			&decimals)
{
	ushort code = 0;
	if(!getParamCodeByName(range, attr, code)){
		return false;
	}

	return getRangeDetailByCode(code, upper, lower, step, decimals);
}

//
// 根据Range的对应code,得到其详细设置
//
bool AprCfg::getRangeDetailByCode(_IN	ushort	code,
								  _OUT	double	&upper,
								  _OUT	double	&lower,
								  _OUT	double	&step,
								  _OUT	ushort	&decimals)
{
	bool ret = false;

	ushort index = 0;
	while(rangeTblm[index].dfmt != NULL){
		if(code == rangeTblm[index].code){
			upper	= rangeTblm[index].hilimit;
			lower	= rangeTblm[index].lowlimit;
			step	= rangeTblm[index].step;

			ret = true;
			break;
		}
		++index;
	}

    if(ret){
        getDecimalsByStep(step, decimals);
    }

	return ret;
}

//
// 根据Range的对应code,得到其unit和coef
//
bool AprCfg::getRangeInfoByCode(_IN		ushort	code, 
								_OUT	QString	&unit,
								_OUT	long	&coef)
{
	ushort index = 0;
	while(rangeTblm[index].dfmt != NULL){
		if(code == rangeTblm[index].code){
			unit = rangeTblm[index].unit;
			coef = rangeTblm[index].coef;
			return true;
		}
		++index;
	}
	
	return false;
}



const rng_tbl_s *AprCfg::getRangeByCode(ushort code)
{
	ushort index = 0;
	while(rangeTblm[index].dfmt != NULL){
		if(code == rangeTblm[index].code){
//			range = &rangeTblm[index];
//			std::cout << "find range by code =====" << range << std::endl;
//			return true;
			return &rangeTblm[index];
		}
		++index;
	}
	return NULL;
}

//
// 根据Device的对应code,得到其在devTblm中的索引号
//
bool AprCfg::getDevIndexByCode(_IN ushort code, _OUT ushort &index)
{
	ushort idx = 0;
	while(devTblm[idx].code != -1){
		if(devTblm[idx].code == code){
			index = idx;
			return true;
		}
		++idx;
	}

	return false;
}


//
// 查找指定ITEM的BIAS/MEAS MODE
//
bool AprCfg::getBiasMeasModeByItem(_IN	const QString	&item,
								   _IN	para_attr_e		attr,
								   _OUT	char			&mode)
{
	ushort index = 0;
	while(paramTblm[index].commandName != NULL){
		if(item == paramTblm[index].commandName){
			if(PM_MRANGE_ATTR == attr){
				mode = paramTblm[index].mmode;
			}else if(PM_BRANGE_ATTR == attr){
				mode = paramTblm[index].bmode;
			}else{
				continue;
			}
			return true;
		}
		++index;
	}

	return false;
}


//// 光量项目查表操作 //////////////////////////////////////////////////////

//=========================================================================
// func: 根据getHueItems的结果创建光量项目的索引
//
// param:
//		citem - citem_t数组，保存建立的索引
//
// return: 建立索引的个数，即在kind中存在的master项目的个数
//=========================================================================
ushort AprCfg::createHueIndex(_IN const program_s& program, _OUT citem_t &citem)
{
	ushort i = 0;

	// 初始化citem数组
	for(; i < MAX_ITEM_QTY; ++i){
		citem[i] = 0;
	}

	i = 0;
	ushort itemno = getHueItems(program, usemitem, true, true);
	while(0 != itemno){
		citem[i++] = itemno;
		itemno = getHueItems(program, usemitem, false, true);
	}

	return i;
}
	
//=========================================================================
// func: 遍历kind中的所有item，看是否有光量项目
//
// param:
//		program - 查找对应的program
//		code - 指定光量项目类型(useMaster,hue,vl,dlm)
//		bFirstItem - 是从kind中的第0个item开始搜索，还是从上次
//					 搜索位置接下去搜索
//		bCheckBias - item的bias value是否不为0才是有效item
//
// return: 返回从搜索位置起的第一个光量item的index
// 		   注意：此index从1开始计数，0表示未搜索到光量item
//=========================================================================
ushort AprCfg::getHueItems(_IN const program_s& program,
						   _IN const short* code, 
                           _IN 		 bool bFirstItem,
						   _IN 		 bool bCheckBias)
{
	static ushort itemIndex = 0;

	if(bFirstItem){
		itemIndex = 0;
	}

	const short* pCode = code;
	ushort i = 0;
	const item_s* item = NULL;
	for(i = itemIndex; i < MAX_ITEM_QTY; ++i){
		item = &program.kinds[0].item[i];
		if(INVALID == item->active){
			return 0;
		}
		
		pCode = code;
		while(0 != *pCode){
			if(*pCode == item->code){
				if(!bCheckBias){
					itemIndex = i + 1; // 这里＋1就是为了下次调用时能从下一个item继续检索
					return itemIndex;
				}else if(0 != item->bvalue){
					itemIndex = i + 1;
					return itemIndex;
				}
			}
			++pCode;
		}
	}

	return 0;
}


//
// 得到Master项目的string list, 用于在calb界面上的显示
//
bool AprCfg::getHueItemsList(_IN	const program_s&	program,
				     		 _OUT	QStringList&		items,
							 _OUT	citem_t&			citem,
							 _OUT	usechn_t&			usechn,
							 _OUT   chnitem_t&			chnitem)
{															
//	citem_t citem = { 0 };

	if(0 == createHueIndex(program, citem)){
		return false;
	}
	
	for(int chIndex = 0; chIndex < MAX_CHANNEL_QTY; ++chIndex){
		usechn[chIndex] = false;
		chnitem[chIndex] = 0;
	}

	const item_s* item;
	QString strItem;
	QString strItemName;

	items.clear();
	ushort i = 0;
	// debug messages
//	for(i = 0; i < MAX_ITEM_QTY; ++i){
//		std::cout << citem[i] << std::endl;
//	}
	for(i = 0; i < MAX_ITEM_QTY; ++i){
		if(0 == citem[i]){
			break;
		}
		item = &program.kinds[0].item[citem[i]-1];
		getParamNameByCode(item->code, strItemName);
		strItem = "CH" + QString::number(item->ch) + "(" + strItemName + "_" + item->suffix + ")";
		items << strItem;

		// 光亮项目使用的通道
		usechn[item->ch-1] = true;

		// 该通道上有几种光量类型
		if(strItemName.contains("HUE") || strItemName.contains("POLH")){ // HUE
			chnitem[item->ch-1] |= MST_HUE;
		}else if(strItemName.contains("VL")){
			chnitem[item->ch-1] |= MST_VL;
		}else if(strItemName.contains("DLM")){
			chnitem[item->ch-1] |= MST_DLM;
		}
	}

	return (i != 0);
}

//============================================================================
// func: 判断某个item是否是光量项目
//
// param:
//		itemCode - 须判断的item的code
//
// return: 该item是否是光亮item
//============================================================================
bool AprCfg::isHueItem(_IN short itemCode)
{
	int i = 0;

	while(usemitem[i] != 0){
		if(itemCode == usemitem[i]){
			return true;
		}
		++i;
	}

	return false;
}
